package top.dbpanda.cmsjpa.learn.rmi.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 动态代理
 */
public class DynamicProxy implements InvocationHandler {
    //可以代理任意类型角色
    private Object obj;
    DynamicProxy(Object obj){
        this.obj = obj;
    }
    public void before() {
        System.out.println("before");
    }

    public void after() {
        System.out.println("after");
    }

    @Override
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {
        this.before();
        Object invoke = method.invoke(obj, objects);
        this.after();
        return invoke;
    }
}
